package examples.hospital;

import jade.core.Agent;
import jade.core.behaviours.Behaviour;

public class PhysicianAgent extends Agent {

    private static final long serialVersionUID = 1L;
    String specialty;

    protected void setup() {
        // Printout a welcome message
        System.out.println("Hello! Physician-agent " + getAID().getName() + " is ready.");
        Object[] args = getArguments();
        if (args != null && args.length > 0) {
            specialty = (String) args[0];
            addBehaviour(new LogBehaviour());
            System.out.println("My area of specialisationis " + specialty);
        } else {
            System.out.println("No specialty has been assigned.");
            doDelete();
        }
    }

    protected void takeDown() {
        System.out.println("Physician-agent " + getAID().getName() + " terminated");
    }

    class LogBehaviour extends Behaviour {

        private static final long serialVersionUID = 1L;

        @Override
        public void action() {
            System.out.println("YES: " + specialty);

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        @Override
        public boolean done() {
            return false;
        }

    }
}